<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use app\modules\Cruise\models\Cruise;
use app\modules\Product\models\ProductRoom;
use app\models\Supplier;

$this->title = "航线生成";
$this->params['breadcrumbs'][] = $this->title;

$cruise = Cruise::find()->where(['status'=>1])->all(); 

?>
<script type="text/javascript" src="/js/excellentexport/excellentexport.min.js"></script>

<div class="product-index">

    <h2 class="page-header">
        <?= Html::encode($this->title) ?>
        <p class="pull-right">
            <!-- ?= Html::a(Yii::t('app.cruise', 'Create Product'), ['create'], ['class' => 'btn btn-success']) ? -->
           
        </p>
    </h2>
   
<!-- </?PHP Pjax::begin(['id'=>'product', 'timeout'=>3000, 'linkSelector'=>'#product a[data-sort], #product a[data-page]']);?> -->
    <p><?php  echo $this->render('line_search', ['model' => $searchModel]); ?></p>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        //'filterModel' => $searchModel,
        'layout'  =>  "{items}\n{pager}",
        'tableOptions' => ['id'=>'mytabel','class' => 'table table-striped table-bordered'],
        'columns' => [
            [ 
                'class' => 'yii\grid\SerialColumn',],
            [
                'label'=>'类型',
                'value' => function ($model) {
                        return Yii::$app->params['product_type'][$model->type];
                    },
            ],
            [
                'label'=>'区域',
                //'attribute' => 'line',
                'value' => function ($model) {
                        return Yii::$app->params['line'][$model->line];
                    },
            ],
            [
                'label'=>'邮轮公司',
                'attribute' => 'cruise.supplier_id',
                'value' => function ($model){
                        $supplier = Supplier::find()->where(['status'=>1])->all(); 
                        $supplier = yii\helpers\ArrayHelper::map($supplier, 'id', 'company');
                        return $supplier[$model->cruise->supplier_id];
                    },
            ],
            [
                'label'=>'邮轮名称',
                'value' =>'cruise.name',
            ],
            [
                'label'=>'团号',
                'value' =>'code',
            ],
            [
                'label'=>'团队名称',
                'value' =>'name',
            ],
            //'code',
            [
                'label'=> '出发日期',
                'value' => function($model){
                    return isset($model->go_time)?date("Y年m月d日",strtotime($model->go_time)):'未设置';
                },
            ],
             [
                'label'=> '返回日期',
                'value' => function($model){
                    return isset($model->return_time)?date("Y年m月d日",strtotime($model->return_time)):'未设置';
                },
            ],
            //'go_time:date',
            //'return_time:date',
            // 'day',
            //'from_city',
             [
                'label'=>'出发城市',
                //'attribute' => 'from_city',
                'value' => function ($model) {
                        return Yii::$app->params['city'][$model->from_city];
                    },
            ],
            //'to_city',
           
             [
                'label'=>'返回城市',
                //'attribute' => 'to_city',
                'value' => function ($model) {
                        return Yii::$app->params['city'][$model->to_city];
                    },
            ],
            // 'line',
            // 'cost:ntext',
            // 'visa:ntext',
            [
                'label'=>'航线价格',
                'value'=> function($model){
                        
                    return yii::$app->formatter->asDecimal(floor($model->minPrice));
                },
            ],
            [
                'label'=>'状态',
                //'attribute' => 'status',
                'filter' =>  Yii::$app->params['status'],
                'value' => function ($model) {
                        return Yii::$app->params['status'][$model->status];
                    },
            ],
           
        ],
        
    ]); ?>
<!-- </?php Pjax::end(); ?> -->
    <div class="col-md-12 text-center">
   <!--   <a type="button" class="btn btn-primary col-md-3" style="position:fixed;bottom: 2%;right:35%" download="航线列表.xls" onclick="return ExcellentExport.excel(this, 'mytabel', '航线列表');"><i class="fa fa-file-excel-o"></i> 生成Excel</a> -->
   <a type="button" class="btn btn-primary col-md-3 download" style="position:fixed;bottom: 2%;right:35%" ><i class="fa fa-file-excel-o"></i> 生成Excel</a>
    </div>
</div>


<?php app\components\JsBlock::begin() ?>
<script type="text/javascript"> 

$(".download").click(function(){
   
    $.ajax({
         type: "get",
         url:"/product/statistic/excel",
         data:$('#line-form').serialize(),// 要提交的表单 
         success: function(msg) {
             var data = $.parseJSON(msg);
             var href = "/product/statistic/load?file_path="+data.file_path+"&file_name="+data.file_name;
            window.location.href = href;
         }
     });
});

</script>
<?php app\components\JsBlock::end() ?>






